define(["PDUtilDir/grid", "PDUtilDir/searchBlock"], function (Grid,
                                                              SearchBlock) {

    function init(cache, detailObj, searchObj) {
        SearchBlock.init('searchBlockId');
        // 初始化
//		var test = [{
//			id: 'abc',
//			orderNo: "123",
//			status: "D_ORDER_STATUS_INITIALIZATION"
//			
//		}];
        var strObj = {
            detail: '<a href="javascript:angular.element(\'#OrderGirdDivId\').scope().detailSupport.run',
            detail_suffix: '">详情</a>',

            doneOrder: '<a href="javascript:angular.element(\'#OrderGirdDivId\').scope().doneOrder.run',
            doneOrder_suffix: '">完成</a>',

            closeOrder: '<a href="javascript:angular.element(\'#OrderGirdDivId\').scope().closeOrder.run',
            closeOrder_suffix: '">关闭</a>',

            cancelOrder: '<a href="javascript:angular.element(\'#OrderGirdDivId\').scope().cancelOrder.run',
            cancelOrder_suffix: '">取消</a>',

            rebackRecode: '<a href="javascript:angular.element(\'#OrderGirdDivId\').scope().rebackRecode.run',
            rebackRecode_suffix: '">退款记录</a>',

            reback: '<a href="javascript:angular.element(\'#OrderGirdDivId\').scope().refundSupport.run',
            reback_suffix: '">退款</a>',

            pay: '<a href="javascript:angular.element(\'#OrderGirdDivId\').scope().paySupport.run',
            pay_suffix: '">支付</a>',

            detailForPayOrder: '<a href="javascript:angular.element(\'#OrderGirdDivId\').scope().detailForPayOrder.run',
            detailForPayOrder_suffix: '">支付详情</a>'

        }, getStr = function (oper, id) {
            return strObj[oper] + '(\'' + id + '\')' + strObj[oper + '_suffix'];
        };
        return Grid({
            id: "OrderGirdDivId",
            pageSize: 10,
            index: true,
            multi: true,
            pagination: true,
            cache: false,
            layout: [{
                name: "订单号",
                field: "orderNo",
                sort: false,
                width: "190px",
                click: function (e) {
                    detailObj.run(e.data.row.id);
                }
            }, {
                name: "班期",
                field: "timeDate",
                sort: true
            }/*, {
				name : "组团社",
				field : "storeName",
				sort : true
			}*/, {
                name: "供应商",
                field: "supplierName",
                sort: true
            }, {
                name: "数量",
                width: "60px",
                field: "quantity"
            }/*, {
				name : "付款金额",
				field : "payment"
			}, {
				name : "支付人",
				field : "paymentPerson"
			}*/, {
                name: "总金额",
                width: "60px",
                field: "totalAmount"
            }/*, {
				name : "完成时间",
				width: "100px",
				field : "timeDate"
			}*/,
                // {
                // name : "备注",
                // field : "comment"
                // },
                {
                    name: "状态",
                    width: "80px",
                    field: "status",
                    format: function (e) {
                        return cache.statusMap.get(e.row.status);
                    }
                }, {
                    name: "创建时间",
                    width: "150px",
                    field: "createTime"
                }, {
                    name: "操作人",
                    width: "80px",
                    field: "createUserName"
                }, {
                    name: "操作",
                    field: "createTime",
                    sort: false,
                    width: '150px',
                    format: function (e) {
                        var data = e.row, id = data.id, orderNo = data.orderNo, status = data.status, str = '';
                        /*
                         * 状态包括：
                         * 待支付(D_ORDER_STATUS_INITIALIZATION)
                         * 部分付款(D_ORDER_STATUS_PARTPAY)
                         * 付款完成(D_ORDER_STATUS_PAYDONE)
                         * 取消订单(D_ORDER_STATUS_CANCEL)
                         * 交易成功(D_ORDER_STATUS_SUCCESS_OK)
                         * 交易关闭(D_ORDER_STATUS_CLOSE)
                         *
                         * 操作包括：
                         * 详情(detail)
                         * 支付(pay)
                         * 取消(cancelOrder)
                         * 完成(doneOrder)
                         * 关闭(closeOrder)
                         * 退款记录(rebackRecode)
                         */

                        /*
                         * 所处状态1
                         *    任何状态
                         * 操作
                         *    详情
                         */
//					str = getStr('detail', id) + str;

                        /*
                         * 所处状态2
                         *    待支付
                         * 操作
                         *    支付，取消
                         */
                        if (status == "D_ORDER_STATUS_INITIALIZATION") {
                            str = getStr('pay', id) + str;
                            str = getStr('cancelOrder', orderNo) + str;
                        }

                        /*
                         * 所处状态3
                         *    部分支付
                         * 操作
                         *    支付，取消
                         */
                        if (status == "D_ORDER_STATUS_PARTPAY") {
                            str = getStr('pay', id) + str;
                            str = getStr('cancelOrder', orderNo) + str;
                        }

                        /*
                         * 所处状态4
                         *    付款完成
                         * 操作
                         *    完成，取消
                         */
                        if (status == "D_ORDER_STATUS_PAYDONE") {
                            str = getStr('doneOrder', orderNo) + str;
                            str = getStr('cancelOrder', orderNo) + str;
                        }

                        /*
                         * 所处状态5
                         *    取消状态
                         * 操作
                         *    详情，关闭
                         */
                        if (status == "D_ORDER_STATUS_CANCEL") {
                            str = getStr('closeOrder', orderNo) + str;
                            str = getStr('reback', orderNo) + str;
                        }

                        /*
                         * 所处状态6
                         *    交易成功
                         * 操作
                         *    关闭
                         */
                        if (status == "D_ORDER_STATUS_SUCCESS_OK") {
                            str = getStr('closeOrder', orderNo) + str;
                        }
                        /*
                         * 所处状态7
                         *    交易关闭
                         * 操作
                         *    详情，退款记录
                         */
                        if (status == "D_ORDER_STATUS_CLOSE") {
                            str = getStr('rebackRecode', orderNo) + str;
                        }

                        /*
                         * 订单支付详情
                         */
                        str += getStr('detailForPayOrder', orderNo);

                        return str;
                    }
                }],
            toolbar: [{
                name: "查询",
                icon: "fa fa-search",
                callback: function (event) {
                    searchObj.run();
                }
            }],
//			data: test
            data: {
                type: 'URL',
                value: getServer()
                + '/flea/hclv/visitor/order/listOrgOder.htmls'
            }
        });
    }

    return {
        init: init
    }
});